<template>
  <div class="sonson">
    <h2>孙子组件</h2>
    <h3>爷爷的钱：{{ money }}</h3>
    <button @click="changeMoney(50)">消费</button>
  </div>
</template>

<script>
/* 
  目标：掌握使用provide函数和inject函数完成后代组件数据通讯
*/
import { inject } from 'vue'
export default {
  name: 'SonSon',
  setup() {
    // 接收祖先组件提供的数据
    const money = inject('money')

    const changeMoney = inject('changeMoney')

    return { money, changeMoney }
  },
}
</script>

<style>

</style>